package com.cn.api.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
import java.util.stream.Collectors;

public class Test {
    String str = new String("good");
    char ch[] = {'a', 'b', 'c'};

//	public static void main(String args[]) {
//		// SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd
//		// HH:mm:ss");
//		// Long time = new Long("1500480000000");
//		// String d = sFormat.format(time);
//		// Date temp = null;
//		// try {
//		// temp = sFormat.parse(d);
//		// } catch (ParseException e) {
//		// // TODO Auto-generated catch block
//		// e.printStackTrace();
//		// }
//		// System.out.println("Format To String(Date):" + d);
//		// System.out.println("Format To Date:" + temp);
//
////		 http://t5app.jzhu.cn/game.html
////		 ?companyid=5
////		 &activityid=1004
////		 &uid=xxx
////		 &nick=xxx
////		 &time=yyyyHHddhhMMss
////		 &key=xxx
//		//
//		// 其中companyid=5
//		// ，activityid=1004
//		// ，uid=用户ID
//		// ，nick=用户昵称
//		// MD5加密，32位小写（MD5规则：companyid + activityid + uid +time+
//		// RequestKey（约定的提交key））
//		// requestkey=CTU800617
//		Date now = new Date();
//		SimpleDateFormat sFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//		String strNow = sFormat.format(now);
//		System.out.println(strNow);
//		String key = "";
//		try {
//			key = StringUtil.md5("5" + "1004" + "1" + strNow + "CTU800617");
//		} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		System.out.println(key);
//		System.out.println("http://t5app.jzhu.cn/game.html?companyid=5&activityid=1004&uid=1&nick=aaa&time=" + strNow + "&key=" + key);
//		// http://t5app.jzhu.cn/game.html?companyid=5&activityid=1004&uid=1&nick=aaa&time=yyyyHHddhhMMss&key=xxx
//	}

    public void change(String str, char ch[]) {
        str = "test ok";
        ch[0] = 'g';
    }


    public static void main(String[] args) {
        PrintTask printTask = new PrintTask(0, 3);
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        forkJoinPool.submit(printTask);
        forkJoinPool.shutdown();
    }

    static class PrintTask extends RecursiveAction {
        private static final int THRESHOLD = 50; //最多只能打印50个数
        private int start;
        private int end;


        public PrintTask(int start, int end) {
            super();
            this.start = start;
            this.end = end;
        }


        @Override
        protected void compute() {

            if (end - start < THRESHOLD) {
                for (int i = start; i < end; i++) {
                    System.out.println(Thread.currentThread().getName() + "的i值：" + i);
                }
            } else {
                int middle = (start + end) / 2;
                PrintTask left = new PrintTask(start, middle);
                PrintTask right = new PrintTask(middle, end);
                //并行执行两个“小任务”
                left.fork();
                right.fork();
            }

        }

    }

    @org.junit.Test
    public void te() {

        List<Member> list = new ArrayList();
        list.add(new Member("1", "张1", "男"));
        list.add(new Member("2", "李2", "男"));
        list.add(new Member("3", "王3", "女"));
        list.add(new Member("4", "刘4", "男"));
        list.add(new Member("5", "周5", "女"));
        list.add(new Member("6", "吴6", "男"));
        System.out.println(list);
        list.stream().filter(m -> (m.getId().contains("2"))).collect(Collectors.toList()).forEach(M -> {
            System.out.println(M.getId());
        });
//        System.out.println(list.stream().filter(m -> (m.getId().contains("2"))).collect(Collectors.toMap(Member::getId)));

    }

    class Member {
        public String id;
        public String name;
        public String sex;

        @Override
        public String toString() {
            return "Member{" +
                    "id='" + id + '\'' +
                    ", name='" + name + '\'' +
                    ", sex='" + sex + '\'' +
                    '}';
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public Member(String id, String name, String sex) {
            this.id = id;
            this.name = name;
            this.sex = sex;
        }
    }

}
